package ua.com.alus.resvac.crm.domen.entities;

import ua.com.alus.resvac.crm.domen.prototype.AccountType;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.List;

/**
 * Abstract account
 * <p/>
 * Created by Usatov Alexey
 */
@Entity
@Table(name = "ACCOUNT")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@NamedQueries(
        {
                @NamedQuery(name = Account.SELECT_BY_USERNAME,
                        query = "select acc from Account acc where acc.userName=:userName")

        }


)
public class Account implements Serializable {

    public static final String SELECT_BY_USERNAME = "ua.com.alus.resvac.crm.domen.entities.Account.selectAccByUsername";

    @Id
    @Column(name = "PK_UUID")
    private String uuid;

    @Column(name = "USERNAME")
    private String userName;

    @Column(name = "PASSWORD")
    private String password;

    @Transient
    private String rePassword;


    @Column(name = "ACC_TYPE")
    @Enumerated(value = EnumType.STRING)
    private AccountType accountType;

    @OneToMany(mappedBy = "account", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private List<Photo> photo;

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRePassword() {
        return rePassword;
    }

    public void setRePassword(String rePassword) {
        this.rePassword = rePassword;
    }

    public AccountType getAccountType() {
        return accountType;
    }

    public void setAccountType(AccountType accountType) {
        this.accountType = accountType;
    }

    public List<Photo> getPhoto() {
        return photo;
    }

    public void setPhoto(List<Photo> photo) {
        if (photo != null) {
            for (Photo currentPhoto : photo) {
                currentPhoto.setAccount(this);
            }
        }
        this.photo = photo;
    }
}
